---@class TBS.SkillMgr
---@field New fun():TBS.SkillMgr
local SkillMgr = TBS.CreateClass("SkillMgr")
---@param actor TBS.Player
function SkillMgr:OnCreate(actor)
    self.actor = actor
    ---@type TBS.Skill[]
    self.skillList = {}     --所有技能
    ---@type TBS.Skill[]
    self.releaseList = {} --释放中的技能
end
function SkillMgr:OnDestroy()
    self.actor = nil
    if self.skillList then
        for k,v in pairs(self.skillList) do
            v:OnDestroy()
        end
    end
    self.skillList = nil
end
function SkillMgr:EndSkill(uniqueId)
    local s = self.releaseList[uniqueId]
    self.releaseList[uniqueId] = nil
    self.skillList[uniqueId] = nil
    if not s then return end
    s:EndSkill()
    TBS.PoolMgr.ReturnSkillToPool(s)
end
function SkillMgr:EndAllSkill(cleanEffect)
    local tb = TablePool.Get()
    for k,v in pairs(self.releaseList) do
        table.insert(tb,v)
    end
    for k,v in pairs(tb) do
        self:EndSkill(v.uniqueId)
        if cleanEffect then
            TBS.EffectMgr.DestroyEffectBySkill(v.uniqueId)
        end
    end
    TablePool.ReleaseDeeper(tb,false)
end
---@return TBS.Skill
function SkillMgr:CreateSkill(skillId,uniqueId)
    local skill = TBS.PoolMgr.GetSkillFromPool(skillId)
    skill:Set(self.actor:GetId(),uniqueId)
    self.skillList[uniqueId] = skill
    return skill
end
---@return TBS.Skill
function SkillMgr:GetSkill(uniqueId)
    return self.skillList[uniqueId]
end
function SkillMgr:DoSkill(uniqueId)
    local s = self.skillList[uniqueId]
    if not s then return end
    local flag = s:DoSkill()
    if flag then
        self.releaseList[uniqueId] = s
    end
end

function SkillMgr:Update(dt)
    for k,v in pairs(self.releaseList) do
        v:Update(dt)
    end
end
function SkillMgr:TurnStart()
    for k,v in pairs( self.skillList) do
        v:TurnStart()
    end
    self:EndAllSkill()
end